#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/2 18:25
# @Author  : 1823218990@qq.com
# @File    : vccmd
# @Software: Pycharm

import subprocess
CODE_ERROR = -1


def exe_cmd(cmd, timeout=10, logger=None):
    try:
        s = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = s.communicate(timeout=timeout)
        code = s.returncode
        if logger is not None and code != 0:
            logger.info("code:{} out:{} err:{}".format(code, stdout, stderr))
        if code != 0:
            return code, "{}".format(stderr.decode('utf-8'))
        else:
            return code, "{}".format(stdout.decode('utf-8'))
    except Exception as e:
        if logger is not None:
            logger.error(e)
        return CODE_ERROR, e


def get_rate():
    """
    ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0:s=x 01.mp4
    :return:
    """